package so.sao.shop.supplier.web.authorized;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import so.sao.shop.supplier.domain.User;
import so.sao.shop.supplier.pojo.Result;
import so.sao.shop.supplier.pojo.SystemContext;
import so.sao.shop.supplier.service.authorized.PermissionService;
import so.sao.shop.supplier.util.JwtTokenUtil;

import java.util.List;

@RestController
@RequestMapping(value = "/permission")
public class PermissionController {

	@Autowired
	private PermissionService permissionService;

	@RequestMapping(value = "/findAll", method = RequestMethod.GET)
	public Result<?> findAll() {
		return permissionService.findAll();
	}

	@RequestMapping(value = "/findAllPermissionTree", method = RequestMethod.GET)
	public Result<?> findAllPermissionTree(Long userId,Long parentId) {
		return permissionService.findAllPermissionTree(userId,parentId,null);
	}

	@RequestMapping(value="/rolePermission",method=RequestMethod.GET)
	public Result<?> selectRolePermission(@RequestParam(value="roleIds[]") List<Long> roleIds) {
		User user = JwtTokenUtil.getCurrentUser();
		return permissionService.selectRolePermission(user.getId(), roleIds);
	}

}
